$(function() {
	jQuery.validator.addMethod("isphone", function(value, element) {   
		return this.optional(element) || /^^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$|(^(13[0-9]|15[0|3|6|7|8|9]|18[8|9]|18[0-9])\d{8}$)/.test(value);   
	}, "请正确填写您的联系电话");

	$("#add_merchant_form").validate({
		errorPlacement:function(error,element) {  
			element.parent().find(".verror").html(error);
		},
		rules:{
			"merchant.merchantNo":{
				required:true,
				rangelength: [4, 20],
				remote: {
					url: base + "admin/merchant/checkMerchantNo.action", 
					type: "POST", 
					data: {"merchant.id": ($("#merchant_id").val()), "merchant.merchantNo": ($("#merchant.merchantNo").val())}
				}
			}, 
			"merchant.merchantName": {
				required:true
			}, 
			"merchant.telephone": {
				required:true,
				isphone:true,
				remote: {
					url: base + "admin/merchant/checkTelephone.action", 
					type: "POST", 
					data: {"merchant.id": ($("#merchant_id").val()), "merchant.telephone": ($("#merchant.telephone").val())}
				}
			}, 
			"merchant.email": {
				email:true,
				remote: {
					url: base + "admin/merchant/checkEmail.action", 
					type: "POST", 
					data: {"merchant.id": ($("#merchant_id").val()), "merchant.email": ($("#merchant.email").val())}
				}
			}, 
			"merchant.address": {
				required:true
			}
		},
		messages:{
			"merchant.merchantNo": {
				required: "请输入供应商编号", 
				rangelength:"长度不能少于{0}和大于{1}个字符",
				remote: "该供应商编号已存在"
			}, 
			"merchant.merchantName": {
				required: "请输入供应商名称"
			}, 
			"merchant.telephone": {
				required:"请输入联系电话",
				isphone:"联系电话格式不正确",
				remote: "该联系电话已存在"
			}, 
			"merchant.email": {
				email: "电子邮箱格式不正确",
				remote: "该电子邮箱已存在"
			}, 
			"merchant.address": {
				required: "请输入联系地址"
			}
		}
	});
});